unit USearchCustomer;

interface

uses
  System.SysUtils, System.Types, System.UITypes, System.Rtti, System.Classes,
  System.Variants, FMX.Types, FMX.Controls, FMX.Forms, FMX.Dialogs,
  FMX.StdCtrls, UDialog, FMX.Edit, FMX.ListBox, FMX.Layouts, FMX.Grid, Data.Db,
  ColumnAlign, DataLayer, Data.SqlExpr, System.Generics.Collections,
  Data.FMTBcd, UModel,
  FMX.Objects;

type
  TSearchCustomer = class(TDialogFrame)
    StringGrid1: TStringGrid;
    Label1: TLabel;
    Label2: TLabel;
    ComboBox1: TComboBox;
    Edit1: TEdit;
    Button1: TButton;
    Button2: TButton;
    ListBoxItem1: TListBoxItem;
    ListBoxItem2: TListBoxItem;
    ListBoxItem3: TListBoxItem;
    ListBoxItem4: TListBoxItem;
    ListBoxItem5: TListBoxItem;
    ListBoxItem6: TListBoxItem;
    ListBoxItem7: TListBoxItem;
    ListBoxItem8: TListBoxItem;
    ListBoxItem9: TListBoxItem;
    ListBoxItem10: TListBoxItem;
    ListBoxItem11: TListBoxItem;
    procedure ComboBox1Change(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure CloseButtonClick(Sender: TObject);

  private
    { Private declarations }
    vipnocol, vipnamecol, telecol, streetnocol, addresscol, suburbcol,
    postcodecol: TTextColumn;
    procedure InitialColumns;
  public
    { Public declarations }
    // TDataModule: TDataModule1;
    CustomerInfo : TCustomerInfo;
    constructor Create(ParentForm: TForm; ParentPanel: TPanel;
      CallBackProc: IProcessDialogResult);
  end;

//  TCustomerGrid = class
//  private
//    ftvipno, ftvipname, fttele, ftstreetno, ftaddress, ftsuburb,
//    ftpostcode: String;
//
//  end;

var
  SearchCustomer: TSearchCustomer;
  // gridlist: TList<TCustomerGrid>;

implementation

{$R *.fmx}

procedure TSearchCustomer.Button1Click(Sender: TObject);
var
  i: Integer;
  searchrow: TList<Integer>;
  j: Integer;
begin
  case ComboBox1.ItemIndex of
    0:
      begin
        for i := 0 to StringGrid1.RowCount do
        begin
          if Pos(Edit1.Text, StringGrid1.Cells[0, i]) <> 0 then
          begin
            searchrow.Add(i);

          end;

        end;

        for i := 0 to searchrow.Count do
        begin
          for j := 0 to 7 do
          begin
            StringGrid1.Cells[j, i] := StringGrid1.Cells[j, searchrow.Items[i]];
          end;

        end;

      end;

  end;
end;

procedure TSearchCustomer.ComboBox1Change(Sender: TObject);

begin
  Label2.Text := 'Search by ' + ComboBox1.Selected.Text;

end;

constructor TSearchCustomer.Create(ParentForm: TForm; ParentPanel: TPanel;
  CallBackProc: IProcessDialogResult);
var
  q: TSQLQuery;
  i: Integer;
  vipnoList: TList<string>;
  strgrid: TStringGrid;
  CustomerInfo: TCustomerInfo;

begin
  inherited Create(ParentForm, ParentPanel, CallBackProc);
  // Initalize StringGrid1 columns
  InitialColumns;
  // Initalize StringGrid1 Data
  CustomerInfo := TCustomerInfo.Create;

  strgrid := StringGrid1;
  Label2.Text := 'Search by ' + ComboBox1.Selected.Text;
  for i := 0 to CustomerInfo.CustomerList.Count - 1 do
  begin
    StringGrid1.Cells[0, i] := CustomerInfo.CustomerList.Items[i].VipNo;
    StringGrid1.Cells[1, i] := CustomerInfo.CustomerList.Items[i].VipName;
    StringGrid1.Cells[2, i] := CustomerInfo.CustomerList.Items[i].tele;
    StringGrid1.Cells[3, i] := CustomerInfo.CustomerList.Items[i].streetno;
    StringGrid1.Cells[4, i] := CustomerInfo.CustomerList.Items[i].address;
    StringGrid1.Cells[5, i] := CustomerInfo.CustomerList.Items[i].suburb;
    StringGrid1.Cells[6, i] := CustomerInfo.CustomerList.Items[i].postcode;
  end;

end;

procedure TSearchCustomer.InitialColumns;
begin
  vipnocol := TTextColumn.Create(StringGrid1);
  vipnamecol := TTextColumn.Create(StringGrid1);
  telecol := TTextColumn.Create(StringGrid1);
  streetnocol := TTextColumn.Create(StringGrid1);
  addresscol := TTextColumn.Create(StringGrid1);
  suburbcol := TTextColumn.Create(StringGrid1);
  postcodecol := TTextColumn.Create(StringGrid1);

  vipnocol.TextAlign := TTextAlign.taLeading;
  vipnamecol.TextAlign := TTextAlign.taLeading;
  telecol.TextAlign := TTextAlign.taLeading;
  streetnocol.TextAlign := TTextAlign.taLeading;
  addresscol.TextAlign := TTextAlign.taLeading;
  suburbcol.TextAlign := TTextAlign.taLeading;
  postcodecol.TextAlign := TTextAlign.taLeading;

  vipnocol.Parent := StringGrid1;
  vipnamecol.Parent := StringGrid1;
  telecol.Parent := StringGrid1;
  streetnocol.Parent := StringGrid1;
  addresscol.Parent := StringGrid1;
  suburbcol.Parent := StringGrid1;
  postcodecol.Parent := StringGrid1;

  vipnocol.Width := 60;
  vipnamecol.Width := 120;
  telecol.Width := 120;
  streetnocol.Width := 90;
  addresscol.Width := 160;
  suburbcol.Width := 80;
  postcodecol.Width := 78;

  vipnocol.Header := '   VIP No.';
  vipnamecol.Header := '           VIP Name';
  telecol.Header := '          TelePhone';
  streetnocol.Header := '  Street Number';
  addresscol.Header := '                  Address';
  suburbcol.Header := '      Suburb';
  postcodecol.Header := '    Post Code';
end;

procedure TSearchCustomer.CloseButtonClick(Sender: TObject);
begin
  inherited;
  CustomerInfo.Free;
end;

end.
